package me.zhengjie.modules.hanzi.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.hanzi.domain.Category;
import me.zhengjie.modules.hanzi.domain.HanziCharacter;
import me.zhengjie.modules.hanzi.service.HanziService;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import me.zhengjie.utils.Result;

@Slf4j
@Tag(name = "分类管理", description = "汉字分类相关接口")
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class CategoryController {
    private final HanziService hanziService;

    @Operation(summary = "获取所有分类")
    @GetMapping("/categories")
    public Result<List<Category>> getCategories() {
        return Result.ok(hanziService.getCategories());
    }

    @Operation(summary = "获取分类下的汉字")
    @GetMapping("/category/{categoryId}/characters")
    public Result<List<HanziCharacter>> getCategoryCharacters(
            @PathVariable String categoryId,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "20") int limit) {
        Page<HanziCharacter> characterPage = hanziService.getCategoryCharacters(categoryId, page, limit);
        return Result.ok(characterPage.getRecords(), characterPage.getTotal(), page, limit);
    }
}